﻿using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using SSN.WebFramework;
using SSN.Utilities.Security;

namespace SSN.WebFrameworkTests
{
    [TestClass]
    public class PageSecurityTest
    {
        [TestMethod]
        public void CRUDPageSecurity()
        {
            TestSecurityContext ctx = new TestSecurityContext();
            PageSecurity ps = new PageSecurity();
            ps.New(ctx);
            ps.AppName = "TestApp";
            ps.AccessLevel = AccessLevel.Change;
            ps.Principle = "thouk";
            ps.PrincipleType = PrincipleType.User;
            ps.Path = "/default.aspx";
            Assert.IsTrue(ps.Save());

            List<PageSecurity> sec = PageSecurity.GetSecurityForPage(ctx, "TestApp", "default.aspx");
            Assert.IsTrue(sec[0].ID == ps.ID);
            sec[0].AccessLevel = AccessLevel.None;
            sec[0].Save();
            sec = PageSecurity.GetSecurityForPage(ctx, "TestApp", "default.aspx");
            Assert.IsTrue(sec[0].AccessLevel == AccessLevel.None);
            sec[0].Delete();
            Assert.IsTrue(PageSecurity.GetSecurityForPage(ctx, "TestApp", "default.aspx").Count == 0);
        }
    }
}
